package ua.kharkov.knure.pereverziev.diploma.db.entity;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import ua.kharkov.knure.pereverziev.diploma.web.util.DateTimeUtil;

public class Route implements Serializable {

	private static final long serialVersionUID = -8730292264174998486L;

	public Route() {
	}

	public Route(final List<Flight> flights) {
		this.flights = flights;
	}

	public Route(final Flight flight) {
		flights = new LinkedList<Flight>();
		flights.add(flight);
	}

	private List<Flight> flights;

	public List<Flight> getFlights() {
		return flights;
	}

	public void setFlights(final List<Flight> flights) {
		this.flights = flights;
	}

	public String getDuration() {
		final Long duration = flights.get(0).getSchedule().getDepartureTime()
				.getTime()
				- (flights.get(flights.size() - 1).getSchedule()
						.getDepartureTime().getTime() - flights
						.get(flights.size() - 1).getSchedule()
						.getFlight_duration().getTime());
		return DateTimeUtil.millisecondsToString(24 * 3600 * 1000 - duration);
	}

	public String getPrice() {
		Float result = 0f;
		for (final Flight flight : flights) {
			result += flight.getPrice();
		}
		return result.toString();
	}

	public Float getPriceFloat() {
		Float result = 0f;
		for (final Flight flight : flights) {
			result += flight.getPrice();
		}
		return result;
	}
}